﻿using Com.JunCaiSoft.API.Common.AssistClass;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Com.JunCaiSoft.API.Permission.Controllers
{
    /// <summary>
    /// 
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class MenuManager : ControllerBase
    {
        /// <summary>
        /// 储存当前用户当前模块
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="Model"></param>
        /// <returns></returns>
        [HttpGet]
        public virtual async Task<ActionResult> SetCurrentModel(Guid currentUser,String Model)
        {
            if (!String.IsNullOrEmpty(Model))
            {
                RedisCacheExtension.Replace(currentUser.ToString() + "-Model", Model);
            }
            else
            {
                RedisCacheExtension.Remove(currentUser.ToString() + "-Model");
            }
            return await Task.Run(() => Content(Model));
        }
        /// <summary>
        /// 获取当前用户当前模块
        /// </summary>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        [HttpGet]
        public virtual async Task<ActionResult> GetCurrentModel(Guid currentUser)
        {

            var Model = RedisCacheExtension.GetStringValue(currentUser.ToString() + "-Model");

            return await Task.Run(() => Content(Model));
        }
        /// <summary>
        /// 储存当前用户当前菜单
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="ActiveMenu"></param>
        /// <returns></returns>
        [HttpGet]
        public virtual async Task<ActionResult> SetCurrentActiveMenu(Guid currentUser, String ActiveMenu)
        {
            if (!String.IsNullOrEmpty(ActiveMenu))
            {
                RedisCacheExtension.Replace(currentUser.ToString() + "-ActiveMenu", ActiveMenu);
            }
            else
            {
                RedisCacheExtension.Remove(currentUser.ToString() + "-ActiveMenu");
            }
            return await Task.Run(() => Content(ActiveMenu));
        }
        /// <summary>
        /// 获取当前用户当前菜单
        /// </summary>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        [HttpGet]
        public virtual async Task<ActionResult> GetCurrentActiveMenu(Guid currentUser)
        {
            var ActiveMenu = RedisCacheExtension.GetStringValue(currentUser.ToString() + "-ActiveMenu");

            return await Task.Run(() => Content(ActiveMenu));
        }
        /// <summary>
        /// 储存当前用户当前打开菜单
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="OpenMenu"></param>
        /// <returns></returns>
        [HttpGet]
        public virtual async Task<ActionResult> SetCurrentOpenMenu(Guid currentUser, String OpenMenu)
        {
            if (!String.IsNullOrEmpty(OpenMenu))
            {
                RedisCacheExtension.Replace(currentUser.ToString() + "-OpenMenu", OpenMenu);
            }
            else
            {
                RedisCacheExtension.Remove(currentUser.ToString() + "-OpenMenu");
            }
            return await Task.Run(() => Content(OpenMenu));
        }
        /// <summary>
        /// 获取当前用户当前打开菜单
        /// </summary>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        [HttpGet]
        public virtual async Task<ActionResult> GetCurrentOpenMenu(Guid currentUser)
        {
            var OpenMenu = RedisCacheExtension.GetStringValue(currentUser.ToString() + "-OpenMenu");

            return await Task.Run(() => Content(OpenMenu));
        }
    }
}
